﻿$(function () {
    var manager = $("#grid").ligerGrid({
        columns: [
            //{
            //    display: '序号',
            //    align: 'center',
            //    width: 50,
            //    minWidth: 50,
            //    render: function (item, i) {
            //        return (i + 1).toString();
            //    }
            //},
            { display: 'ID', name: 'Id', isSort: false, width: 40, align: 'left', hide: true },
            {
                display: '标题',
                align: 'left',
                width: 250,
                minWidth: 100,
                name: 'Title'
            },
            { display: '链接地址', name: 'Url', isSort: false, width: 250, align: 'left' },
            {
                display: '图片', isSort: false, width: 250, render: function (rowdata, rowindex, value) {
                    var h = "";
                    h += "<a href='" + rowdata.ImgUrl + "'>查看图片</a> ";
                    return h;
                }
            },
            {
                display: '操作', isSort: false, width: 120, render: function (rowdata, rowindex, value) {
                    var h = "";
                    h += "<a href='javascript:beginEdit(" + rowdata.Id + ")'>修改</a> ";
                    h += "<a href='javascript:deleteRow(" + rowdata.Id + ")'>删除</a> ";
                    return h;
                }
            }


        ],
        width: '99.85%',
        height:
            '100%',
        heightDiff:
            -20,
        pageSizeOptions:
            [5, 10, 15, 20],
        //data: TreeDeptData,
        alternatingRow:
            false,
        url:
            "/Links/Links?np=" + $("#cc").val(),
        headerRowHeight:
            26,
        checkbox: false,
        autoCheckChildren: false,
        dataAction: "server",
        rowAttrRender:
            function (item, index) {
                return "";
            }
    }


);


    $("#pt").click(function () {
        manager.options.parms = [
            { name: 'title', value: $("#searchTitle").val() },
        ];
        manager.options.newPage = 1;
        manager.loadData();
    });
});

function beginEdit(rowid) {

    location.href = "Edit/" + rowid;
}

function deleteRow(rowid) {
    if (confirm('确定删除?')) {
        $.ajax({
            url: '/Links/DeleteLink',
            dataType: 'json',
            type: 'post',
            data: { id: rowid },
            traditional: true,
            success: function (callback) {
                if (callback) {
                    $.ligerDialog.alert('删除成功', function (yes) {
                        $("#grid").ligerGetGridManager().loadData();
                    });
                }
                else {
                    $.ligerDialog.error('删除失败');
                }
            },
            error: function (ex) {
                $.ligerDialog.error('删除失败');
            }
        });
    }
}